Introduction into searching with Manticore Search

Search is a key functionality of Manticore Search. You can:

General syntax

SQL:

SELECT ... [OPTION <optionname>=<value> [ , ... ]]

HTTP:

POST /search
{   
    "index" : "index_name",
    "options":   
    {
      ...
    }
}

Full-text matching

MATCH

The MATCH clause allows to perform full-text searches in text fields. The query string at input is tokenized using same settings applied to the text during indexing. In addition to tokenization of input text, the query string supports a number of full-text operators that allow enforcing different rules on how keywords should provide a valid match.

The full-text match clauses can be combined with attribute filters as an AND boolean. OR relation between full-text matches and attribute filters are not supported.

The match query is always executed first in the filtering process, followed by the attribute filters. The attribute filters are applied on the result set of the match query. A query without a match clause is called a fullscan.

There must be at most one MATCH() in the SELECT clause.

Using the full-text query syntax matching is performed over all indexed text fields of a document, unless the expression requires to be match within a field (like phrase search) or limited by field operators.

SQL

SELECT * FROM index WHERE MATCH('cats|birds');

SELECT statement uses MATCH clause for performing full-text searches. It accepts an input string in which all full-text operators are available.

‹›
  • SQL
SQL
📋
SELECT * FROM myindex WHERE MATCH('"find me fast"/2');
‹›
Response
+------+------+----------------+
| id   | gid  | title          |
+------+------+----------------+
|    1 |   11 | first find me  |
|    2 |   12 | second find me |
+------+------+----------------+
2 rows in set (0.00 sec)

HTTP JSON

Full-text matching is available in the /search endpoint and in HTTP-based clients. The following clauses can be used for performing full-text matches:

match

"match" is a simple query that matches the specified keywords in the specified fields

"query":
{
  "match": { "field": "keyword" }
}

You can specify a list of fields:

"match":
{
  "field1,field2": "keyword"
}

Or you can use _all or * to search all fields.

You can search all fields except one using "!field":

"match":
{
  "!field1": "keyword"
}

By default keywords are combined using the OR operator. However, you can change that behaviour using the "operator" clause:

"query":
{
  "match":
  {
    "content,title":
    {
      "query":"keyword",
      "operator":"or"
    }
  }
}

"operator" can be set to "or" or "and".

match_phrase

"match_phrase" is a query that matches the entire phrase. It is similar to a phrase operator in SQL. Here's an example:

"query":
{
  "match_phrase": { "_all" : "had grown quite" }
}

query_string

"query_string" accepts an input string as a full-text query in MATCH() syntax

"query":
{
  "query_string": "Church NOTNEAR/3 street"
}

Combining full-text filtering with other filters

All full-text match clauses can be combined with must, must_not and should operators of an HTTP bool query.

‹›
  • match
  • match_phrase
  • query_string
  • PHP
  • Python
  • javascript
  • Java
📋
POST /search
-d
'{   
    "index" : "hn_small",
    "query":
    {
        "match":
        {
            "*" : "find joe"
        }
    },
    "_source": ["story_author","comment_author"],
    "limit": 1
}'
‹›
Response
{
   "took" : 3,
   "timed_out" : false,
   "hits" : {
      "hits" : [
         {
            "_id" : "668018",
            "_score" : 3579,
            "_source" : {
               "story_author" : "IgorPartola",
               "comment_author" : "joe_the_user"
            }
         }
      ],
      "total" : 88063,
      "total_relation" : "eq"
   }
}